<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Output Filters</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="plugins.html" title="Chapter 18. Extending Smarty With Plugins">
<link rel="prev" href="plugins.prefilters.postfilters.html" title="Prefilters/Postfilters">
<link rel="next" href="plugins.resources.html" title="Resources">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Output Filters</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="plugins.prefilters.postfilters.html">Prev</a> </td>
<th width="60%" align="center">Chapter 18. Extending Smarty With Plugins</th>
<td width="20%" align="right"> <a accesskey="n" href="plugins.resources.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Output Filters">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="plugins.outputfilters"></a>Output Filters</h2></div></div></div>
<p>
     Output filter plugins operate on a template's output, after the
     template is loaded and executed, but before the output is displayed.
    </p>
<div class="funcsynopsis">
<table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" class="funcprototype-table">
<tr>
<td><code class="funcdef">string <b class="fsfunc">smarty_outputfilter_name</b>(</code></td>
<td>
<var class="pdparam">$template_output</var>, </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<var class="pdparam">$template</var><code>)</code>;</td>
<td> </td>
</tr>
</table>
<div class="paramdef-list">
<code>string <var class="pdparam">$template_output</var></code>;<br><code>object <var class="pdparam">$template</var></code>;</div>
<div class="funcprototype-spacer"> </div>
</div>
<p>
     The first parameter to the output filter function is the template
     output that needs to be processed, and the second parameter is the
     instance of Smarty invoking the plugin. The plugin is supposed to do
     the processing and return the results.
    </p>
<div class="example">
<a name="id465465"></a><p class="title"><b>Example 18.9. An output filter plugin</b></p>
<div class="example-contents"><pre class="programlisting">

&lt;?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     outputfilter.protect_email.php
 * Type:     outputfilter
 * Name:     protect_email
 * Purpose:  Converts @ sign in email addresses to %40 as
 *           a simple protection against spambots
 * -------------------------------------------------------------
 */
 function smarty_outputfilter_protect_email($output, Smarty_Internal_Template $template)
 {
     return preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
                         '$1%40$2', $output);
 }
?&gt;

     </pre></div>
</div>
<br class="example-break"><p>
     See also
     <a class="link" href="api.register.filter.html" title="registerFilter()">
     <code class="varname">registerFilter()</code></a>,
     <a class="link" href="api.unregister.filter.html" title="unregisterFilter()">
     <code class="varname">unregisterFilter()</code></a>.
     </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="plugins.prefilters.postfilters.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="plugins.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="plugins.resources.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Prefilters/Postfilters </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Resources</td>
</tr>
</table>
</div>
</body>
</html>
